package com.stylefeng.guns.modular.system.controller;

import com.github.pagehelper.PageInfo;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.small.dto.ConsumerCommentDTO;
import com.stylefeng.guns.modular.system.model.ConsumerComment;
import com.stylefeng.guns.modular.system.service.IConsumerCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 用户评论控制器
 *
 * @author fengshuonan
 * @Date 2019-09-09 21:57:34
 */
@Controller
@RequestMapping("/consumerComment")
public class ConsumerCommentController extends BaseController {

    private String PREFIX = "/system/consumerComment/";

    @Autowired
    private IConsumerCommentService consumerCommentService;

    /**
     * 跳转到用户评论首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "consumerComment.html";
    }

    /**
     * 跳转到添加用户评论
     */
    @RequestMapping("/consumerComment_add")
    public String consumerCommentAdd() {
        return PREFIX + "consumerComment_add.html";
    }

    /**
     * 跳转到修改用户评论
     */
    @RequestMapping("/consumerComment_update/{consumerCommentId}")
    public String consumerCommentUpdate(@PathVariable Integer consumerCommentId, Model model) {
        ConsumerComment consumerComment = consumerCommentService.selectById(consumerCommentId);
        model.addAttribute("item",consumerComment);
        LogObjectHolder.me().set(consumerComment);
        return PREFIX + "consumerComment_edit.html";
    }

    /**
     * 获取用户评论列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return consumerCommentService.selectList(null);
    }

    /**
     * @api {get} /consumerComment/add  新增用户评论
     * @apiName  addConsumerComment
     * @apiGroup ConsumerComment
     *
     *
     *
     * @apiParam  {Number}  createTime  评论创建时间毫秒.
     * @apiParam  {String}  contant  评论内容.
     * @apiParam  {Number}  grade  评论分数Double.
     * @apiParam  {Number}  consumerId  用户id.
     * @apiParam  {Number}  artificerId  技师id.
     *
     * @apiSuccessExample {json} Success-Response:
     *      HTTP/1.1 200 OK
     *    {
     * 		"message":"操作成功",
     * 	    "code":"200"
     *    }
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(ConsumerComment consumerComment) {
        consumerCommentService.insert(consumerComment);
        return SUCCESS_TIP;
    }

    /**
     * 删除用户评论
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer consumerCommentId) {
        consumerCommentService.deleteById(consumerCommentId);
        return SUCCESS_TIP;
    }

    /**
     * 修改用户评论
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(ConsumerComment consumerComment) {
        consumerCommentService.updateById(consumerComment);
        return SUCCESS_TIP;
    }

    /**
     * 用户评论详情
     */
    @RequestMapping(value = "/detail/{consumerCommentId}")
    @ResponseBody
    public Object detail(@PathVariable("consumerCommentId") Integer consumerCommentId) {
        return consumerCommentService.selectById(consumerCommentId);
    }

    /**
     * @api {GET} /consumerComment/searchList/{consumerCommentId}  评论列表
     * @apiName  searchList
     * @apiGroup ConsumerComment
     *
     * @apiParam {Number} pageCount  每页多少条.
     * @apiParam {Number} currentCount  当前多少页.
     * @apiParam {Number} artificerId    技师id.
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     * 	"endRow": 4,
     * 	"firstPage": 1,
     * 	"hasNextPage": false,
     * 	"hasPreviousPage": false,
     * 	"isFirstPage": true,
     * 	"isLastPage": true,
     * 	"lastPage": 1,
     * 	"list": [
     *                {
     * 			"artificerId": 1,
     * 			"consumerId": 1,
     * 			"contant": "下次会再来2",
     * 			"createTime": "2019-09-19 00:08:12",
     * 			"grade": 3.0,
     * 			"id": 3
     *        },
     *        {
     * 			"artificerId": 1,
     * 			"consumerId": 1,
     * 			"contant": "下次会再来3",
     * 			"createTime": "2019-09-19 00:08:12",
     * 			"grade": 1.0,
     * 			"id": 4
     *        },
     *        {
     * 			"artificerId": 1,
     * 			"consumerId": 1,
     * 			"contant": "下次会再来",
     * 			"createTime": "2019-09-09 00:08:12",
     * 			"grade": 5.0,
     * 			"id": 2
     *        },
     *        {
     * 			"artificerId": 1,
     * 			"consumerId": 1,
     * 			"contant": "技术号可以值得推荐",
     * 			"createTime": "2019-09-09 00:08:04",
     * 			"grade": 4.0,
     * 			"id": 1
     *        }
     * 	],
     * 	"navigateFirstPage": 1,
     * 	"navigateLastPage": 1,
     * 	"navigatePages": 8,
     * 	"navigatepageNums": [
     * 		1
     * 	],
     * 	"nextPage": 0,
     * 	"pageNum": 1,
     * 	"pageSize": 5,
     * 	"pages": 1,
     * 	"prePage": 0,
     * 	"size": 4,
     * 	"startRow": 1,
     * 	"total": "4"
     * }
     */
    @RequestMapping(value = "/searchList/{artificerId}")
    @ResponseBody
    public PageInfo<ConsumerComment> searchList(@PathVariable("artificerId") Integer artificerId
            ,@RequestParam(defaultValue = "10",value = "pageCount")Integer pageCount,
                                                @RequestParam(defaultValue = "1",value = "currentCount")Integer  currentCount) {
        return consumerCommentService.searchList(artificerId,pageCount,currentCount);
    }

    /**
     * 可扩展列表查询
     * @param artificerId
     * @param pageCount
     * @param currentCount
     * @return
     */
    @RequestMapping(value = "/searchListDto/{artificerId}")
    @ResponseBody
    public PageInfo<ConsumerCommentDTO> searchListDto(@PathVariable("artificerId") Integer artificerId
            , @RequestParam(defaultValue = "10",value = "pageCount")Integer pageCount,
                                                      @RequestParam(defaultValue = "1",value = "currentCount")Integer  currentCount) {
        return consumerCommentService.searchDtoList(artificerId,pageCount,currentCount);
    }
}
